/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.transformation.editor.model;

// imports:
import edu.pku.sei.modeler.model.common.AbstractFactory;
import edu.pku.sei.modeler.model.core.MetaAttribute;
import edu.pku.sei.modeler.model.core.MetaClass;
import edu.pku.sei.modeler.model.core.MetaElement;
import edu.pku.sei.modeler.model.core.MetaGeneralization;
import edu.pku.sei.modeler.model.core.MetaPackage;
import edu.pku.sei.modeler.model.core.MetaPrimitiveType;
import edu.pku.sei.modeler.model.core.MetaReference;
import edu.pku.sei.transformation.editor.model.constraint.Constraint;
import edu.pku.sei.transformation.editor.model.constraint.ConstraintConnection;
import edu.pku.sei.transformation.editor.model.execution.AtomicTransformationExecution;
import edu.pku.sei.transformation.editor.model.execution.ControlFlow;
import edu.pku.sei.transformation.editor.model.execution.ControlNode;
import edu.pku.sei.transformation.editor.model.execution.DecisionNode;
import edu.pku.sei.transformation.editor.model.execution.Model;
import edu.pku.sei.transformation.editor.model.execution.ObjectFlow;
import edu.pku.sei.transformation.editor.model.execution.Pin;
import edu.pku.sei.transformation.editor.model.execution.RuleExecution;
import edu.pku.sei.transformation.editor.model.execution.TransformationExecution;
import edu.pku.sei.transformation.editor.model.goal.Description;
import edu.pku.sei.transformation.editor.model.goal.GoalRelationship;
import edu.pku.sei.transformation.editor.model.goal.TransformationGoal;
import edu.pku.sei.transformation.editor.model.implement.TransformationCode;
import edu.pku.sei.transformation.editor.model.pattern.Pattern;
import edu.pku.sei.transformation.editor.model.test.CheckPoint;
import edu.pku.sei.transformation.editor.model.test.CheckPointOperand;
import edu.pku.sei.transformation.editor.model.test.TestCase;
import edu.pku.sei.transformation.editor.model.variable.ConnectionVariable;
import edu.pku.sei.transformation.editor.model.variable.ObjectVariable;
import edu.pku.sei.transformation.editor.model.variable.PrimitiveTypeVariable;

/**
 * @generated
 * 
 */
public class ModelFactory extends AbstractFactory {
	private int objectVariableCount = 0;
	private int connectionVariableCount = 0;
	private int transformationCount = 0;
	private int ruleCount = 0;

	public Object createRootElement(boolean register) {
		return null;
	}

	public Object createElement(String typeString, boolean register) {
		MetaElement element = null;
		elementCount++;
		if (typeString.equals(ModelPackage.__METAPACKAGE__)) {
			element = new MetaPackage();
		} else if (typeString.equals(ModelPackage.__METAMODEL__)) {
			element = new MetaModel();
		} else if (typeString.equals(ModelPackage.__METACLASS__)) {
			element = new MetaClass();
		} else if (typeString.equals(ModelPackage.__METAATTRIBUTE__)) {
			element = new MetaAttribute();
		} else if (typeString.equals(ModelPackage.__METAPRIMITIVETYPE__)) {
			element = new MetaPrimitiveType();
		} else if (typeString.equals(ModelPackage.__METAREFERENCE__)) {
			element = new MetaReference();
		} else if (typeString.equals(ModelPackage.__METAGENERALIZATION__)) {
			element = new MetaGeneralization();
		}

		else if (typeString.equals(ModelPackage.__MODEL_TYPE__)) {
			element = new ModelType();
		} else if (typeString.equals(ModelPackage.__COMPETIBLE__)) {
			element = new Compatiable();
		} else if (typeString.equals(ModelPackage.__ATOMIC_TRANSFORMATION__)) {
			transformationCount++;
			element = new AtomicTransformation();
			((Transformation) element).setName("transformation"
					+ transformationCount);
		} else if (typeString.equals(ModelPackage.__COMPOSITE_TRANSFORMATION__)) {
			transformationCount++;
			element = new CompositeTransformation();
			((Transformation) element).setName("transformation"
					+ transformationCount);
		} else if (typeString
				.equals(ModelPackage.__TRANSFORMATION_FORMAL_PARAMETER__)) {
			element = new TransformationFormalParameter();
		} else if (typeString.equals(ModelPackage.__MODEL__)) {
			element = new Model();
		} else if (typeString.equals(ModelPackage.__KEY__)) {
			element = new Key();
		} else if (typeString.equals(ModelPackage.__RULE__)) {
			ruleCount++;
			element = new Rule();
			((Rule) element).setName("rule" + ruleCount);
		} else if (typeString.equals(ModelPackage.__GRAPHICAL_DOMAIN__)) {
			element = new GraphicalDomain();
		} else if (typeString.equals(ModelPackage.__DOMAIN_CONNECTION__)) {
			element = new DomainConnection();
		} else if (typeString.equals(ModelPackage.__PATTERN__)) {
			element = new Pattern();
		} else if (typeString.equals(ModelPackage.__CONNECTION_VARIABLE__)) {
			this.connectionVariableCount++;
			element = new ConnectionVariable();
			((ConnectionVariable) element).setName("connection"
					+ this.connectionVariableCount);
		} else if (typeString.equals(ModelPackage.__OBJECT_VARIABLE__)) {
			this.objectVariableCount++;
			element = new ObjectVariable();
			((ObjectVariable) element).setName("object"
					+ this.objectVariableCount);
		} else if (typeString.equals(ModelPackage.__PRIMITIVE_TYPE_VARIABLE__)) {
			element = new PrimitiveTypeVariable();
		}

		else if (typeString.equals(ModelPackage.__PRECONDITION_INVOKE__)) {
			element = new RuleInvoke(RuleInvoke.RULE_PRECONDITION);
		}

		else if (typeString.equals(ModelPackage.__POSTCONDITION_INVOKE__)) {
			element = new RuleInvoke(RuleInvoke.RULE_POSTCONDITION);
		}

		else if (typeString.equals(ModelPackage.__COMMENT_CONNECTION__)) {
			element = new CommentConnection();
		}

		else if (typeString.equals(ModelPackage.__RULE_INVOKE_PARAMETER__)) {
			element = new RuleInvokeParameter();
		} else if (typeString.equals(ModelPackage.__EXPRESSION__)) {
			element = new Expression();
		} else if (typeString.equals(ModelPackage.__LITERAL_TEMPLATE__)) {
			element = new Comment();
		}
		// execution
		else if (typeString.equals(ModelPackage.__TRANSFROMATION_EXECUTION__)) {
			element = new TransformationExecution();
		} else if (typeString
				.equals(ModelPackage.__ATOMIC_TRANSFROMATION_EXECUTION__)) {
			element = new AtomicTransformationExecution();
		} else if (typeString.equals(ModelPackage.__RULE_EXECUTION__)) {
			element = new RuleExecution();
		} else if (typeString.equals(ModelPackage.__CONTROLFLOW__)) {
			element = new ControlFlow();
		} else if (typeString.equals(ModelPackage.__OBJECTFLOW__)) {
			element = new ObjectFlow();
		} else if (typeString.equals(ModelPackage.__FORK__)) {
			element = new ControlNode(ControlNode.CONTROL_FORK);
		} else if (typeString.equals(ModelPackage.__JOIN__)) {
			element = new ControlNode(ControlNode.CONTROL_JOIN);
		} else if (typeString.equals(ModelPackage.__DICISION__)) {
			element = new DecisionNode();
		} else if (typeString.equals(ModelPackage.__MERGE__)) {
			element = new ControlNode(ControlNode.CONTROL_MERGE);
		} else if (typeString.equals(ModelPackage.__INITIAL__)) {
			element = new ControlNode(ControlNode.CONTROL_INITIAL);
		} else if (typeString.equals(ModelPackage.__FINAL__)) {
			element = new ControlNode(ControlNode.CONTROL_FINAL);
		} else if (typeString.equals(ModelPackage.__PIN__)) {
			element = new Pin();
		}

		else if (typeString.equals(ModelPackage.__EXTEND__)) {
			element = new TransformationExtend();
		} else if (typeString.equals(ModelPackage.__COMPOSITION__)) {
			element = new TransformationComposition();
		} else if (typeString.equals(ModelPackage.__TYPED_MODEL__)) {
			element = new TypedModel();
		} else if (typeString.equals(ModelPackage.__OVERRIDE__)) {
			element = new RuleOverride();
		}
		// requirement
		else if (typeString.equals(ModelPackage.__TRANSFORMATION_GOAL__)) {
			element = new TransformationGoal();
		} else if (typeString
				.equals(ModelPackage.__TRANSFORMATION_OPTIONAL_GOAL__)) {
			element = new TransformationGoal();
			((TransformationGoal) element).setOptional(true);
		} else if (typeString.equals(ModelPackage.__CONSTRAINT__)) {
			element = new Constraint();
		} else if (typeString.equals(ModelPackage.__REQUIRE_DESCRIPTION__)) {
			element = new Description();
		} /*
		 * else if (typeString.equals(ModelPackage.__REFINEMENT__)) { element =
		 * new Refinement(); }
		 */else if (typeString.equals(ModelPackage.__CONSTRAINT_CONNECTION__)) {
			element = new ConstraintConnection();
		} else if (typeString.equals(ModelPackage.__GOAL_DEPENDENT__)) {
			element = new GoalRelationship();
			((GoalRelationship) element).setType(GoalRelationship.TYPE_DEPEND);
		} else if (typeString.equals(ModelPackage.__GOAL_INCLUDE__)) {
			element = new GoalRelationship();
			((GoalRelationship) element).setType(GoalRelationship.TYPE_INCLUDE);
		}
		// end requirement

		// test
		else if (typeString.equals(ModelPackage.__CHECK_POINT__)) {
			element = new CheckPoint();
		} else if (typeString.equals(ModelPackage.__TEST_CASE__)) {
			element = new TestCase();
		} else if (typeString.equals(ModelPackage.__CHECK_POINT_CONNECTION__)) {
			element = new CheckPointOperand();
		}
		// end test

		else if (ModelPackage.__TRANSFORMATION_CODE__.equals(typeString)) {
			element = new TransformationCode();
		}
		
		if (element == null)
			return null;
		element.setElementID(elementCount);
		if (register) {
			registerToPackage(element, typeString);
		}
		if (model != null)
			element.setModel(model);
		return element;
	}

	public MetaPackage createMetaPackage() {
		return (MetaPackage) createElement(ModelPackage.__METAPACKAGE__, true);
	}

	public MetaModel createMetaModel() {
		return (MetaModel) createElement(ModelPackage.__METAMODEL__, true);
	}

	public Pattern createPattern() {
		return (Pattern) createElement(ModelPackage.__PATTERN__, true);
	}

	public Key createKey() {
		return (Key) createElement(ModelPackage.__KEY__, true);
	}

	public Transformation createTransformation() {
		return (Transformation) createElement(
				ModelPackage.__ATOMIC_TRANSFORMATION__, true);
	}

	public DomainConnection createRelationConnection() {
		return (DomainConnection) createElement(
				ModelPackage.__DOMAIN_CONNECTION__, true);
	}

	public ConnectionVariable createTemplateConnection() {
		return (ConnectionVariable) createElement(
				ModelPackage.__CONNECTION_VARIABLE__, true);
	}

	public RuleInvoke createRelationInvoke() {
		return (RuleInvoke) createElement(ModelPackage.__PRECONDITION_INVOKE__,
				true);
	}

	public MetaClass createMetaClass() {
		return (MetaClass) createElement(ModelPackage.__METACLASS__, true);
	}

	public MetaAttribute createMetaAttribute() {
		return (MetaAttribute) createElement(ModelPackage.__METAATTRIBUTE__,
				true);
	}

	public MetaPrimitiveType createMetaPrimitiveType() {
		return (MetaPrimitiveType) createElement(
				ModelPackage.__METAPRIMITIVETYPE__, true);
	}

	public MetaReference createMetaReference() {
		return (MetaReference) createElement(ModelPackage.__METAREFERENCE__,
				true);
	}

	public MetaGeneralization createMetaGeneralization() {
		return (MetaGeneralization) createElement(
				ModelPackage.__METAGENERALIZATION__, true);
	}

	public Model createTypedModel() {
		return (Model) createElement(ModelPackage.__MODEL__, true);
	}
	
	public TransformationCode createTransformationCode() {
		return (TransformationCode)createElement(ModelPackage.__TRANSFORMATION_CODE__, true);
	}
}